package com.ysd.lis.service.bac.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.bac.BacDrugResultSenrole;
import com.ysd.lis.entity.bac.BacDrugResultSenroleDetails;
import com.ysd.lis.entity.bac.BacInterpretationCodeDict;
import com.ysd.lis.mapper.bac.BacDrugResultSenroleDetailsMapper;
import com.ysd.lis.service.bac.BacDrugResultSenroleDetailsService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wh
 * @since 2025-04-26
 */
@Service
public class BacDrugResultSenroleDetailsServiceImpl extends ServiceImpl<BacDrugResultSenroleDetailsMapper, BacDrugResultSenroleDetails> implements BacDrugResultSenroleDetailsService {

    @Override
    public Result findSenroleDetailsList(String roleCode) {
        MPJLambdaWrapper<BacDrugResultSenroleDetails> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(BacDrugResultSenroleDetails.class)
                .selectAs(BacInterpretationCodeDict::getName, BacDrugResultSenroleDetails::getSensitiveNa)
                .leftJoin(BacInterpretationCodeDict.class, "sa",
                        p -> p.eq(BacInterpretationCodeDict::getCode, BacDrugResultSenroleDetails::getSensitiveNo).eq(BacInterpretationCodeDict::getDelFlag, 0));
        queryWrapper.eq(BacDrugResultSenroleDetails::getDelFlag, 0)
                .eq(BacDrugResultSenroleDetails::getRoleCode, roleCode)
                .orderByAsc(BacDrugResultSenroleDetails::getSeq);
        List<BacDrugResultSenroleDetails> ruleList = this.baseMapper.selectList(queryWrapper);
        return Result.succ(1, "查询成功", ruleList);
    }

    @Override
    public Result saveOrUpdateSenroleDeatils(List<BacDrugResultSenroleDetails> list) {
        boolean b = this.saveOrUpdateBatch(list);
        if (b) {
            return Result.succ(1, "成功", null);
        } else {
            return Result.fail(400, "失败", "");
        }
    }

    @Override
    public Result deleteSenroleRuleDetails(BacDrugResultSenroleDetails bacDrugResultSenroleDetails) {
        boolean b = this.removeById(bacDrugResultSenroleDetails.getId());
        if (b) {
            return Result.succ(1, "成功", null);
        } else {
            return Result.fail(400, "失败", "");
        }
    }
}
